<?php
/**
 * Description: 轮播图设置
 * User: devforma
 * Date: 2016/11/7
 * Time: 10:54
 */

class GetCarousel implements iController  {

    private $unpurchasedUrl;

    public function __construct() {
        $this->unpurchasedUrl = 'zhiboke@'. YG_MOBILE_SECURE_URL .'/index.html#/live/unpurchased?course_id=';
    }

    /**
     * api请求处理主函数
     * @param array $queryArgs 就是$_REQUEST变量
     * @return array api返回结果，必须含response_code
     */
    public function output($queryArgs) {
        $data = [
            'written' => [],
            'interview' => []
        ];

        $writtenCarousel = getOption('dailyexam_promote_written');
        if (is_array($writtenCarousel)) {
            foreach ($writtenCarousel as $item) {
                if (empty($item['img'])) continue;

                $targetContent = $item['targetDef'];
                if ($item['jumpTarget'] == 'app' && strpos($item['targetDef'], 'zhiboke@') !== false) { //直播课路径
                    $targetContent = $this->unpurchasedUrl . substr($item['targetDef'], 8);

                }

                $data['written'][] = [
                    'img_url' => $item['img'],
                    'target_type' => $item['jumpTarget'],
                    'target_content' => $targetContent
                ];
            }
        }

        $interviewCarousel = getOption('dailyexam_promote_interview');
        if (is_array($interviewCarousel)) {
            foreach ($interviewCarousel as $item) {
                if (empty($item['img'])) continue;

                $targetContent = $item['targetDef'];
                if ($item['jumpTarget'] == 'app' && strpos($item['targetDef'], 'zhiboke@') !== false) { //直播课路径
                    $targetContent = $this->unpurchasedUrl . substr($item['targetDef'], 8);
                }

                $data['interview'][] = [
                    'img_url' => $item['img'],
                    'target_type' => $item['jumpTarget'],
                    'target_content' => $targetContent
                ];
            }
        }

        return genOutput(1, $data);
    }
}

